/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.cicp.collector.common;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.sinodata.bsm.cicp.collector.Collector;
import com.sinodata.bsm.cicp.exception.CollectorException;
import com.sinodata.bsm.common.vo.ResPropertyValue;
import com.sinodata.bsm.common.vo.ResPropertyValue.PropValue;

/**
 * <p>
 * Description: 通用网络设备采集器，通过ping命令测试目标设备是否可以连通。如果丢包率或者延时大于设置的阀值PACKET_LOSS_RATE，DELAY，认为无法连通。
 *              程序返回：连通性，延时，丢包率
 * </p>
 *
 * @author wangpeng
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-9-27 上午11:22:30          wangpeng        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public class NetworkEquipment extends Collector {

    private static final Logger logger = Logger.getLogger(NetworkEquipment.class);

    @Override
    public List<ResPropertyValue> collect(String ip) throws CollectorException {
        List<ResPropertyValue> tempValue = null;
        CmdServerPing cmdServerPing = new CmdServerPing();
        tempValue = cmdServerPing.getPingResult(ip, ip);//tempValue = cmdServerPing.getPingResult(null, ip);
        String isConnection = "连接";
        List<ResPropertyValue> values = new ArrayList<ResPropertyValue>();
        if (tempValue != null) {
            PropValue[] result = tempValue.get(0).getValues();
            if (Double.valueOf(result[2].value) == 100) {
                isConnection = "断开";
            }
            ResPropertyValue propertyValueX = new ResPropertyValue();
            String[] propMetas = getPropMeta();
            ResPropertyValue.PropValue[] propValues = new ResPropertyValue.PropValue[propMetas.length];
            propValues[0] = ResPropertyValue.createPropValue(isConnection, propMetas[0]);
            propValues[1] = ResPropertyValue.createPropValue(result[5].value, propMetas[1]);
            propValues[2] = ResPropertyValue.createPropValue(result[2].value, propMetas[2]);
            propertyValueX.setValues(propValues);
            values.add(propertyValueX);
        }
        return values;
    }

    @Override
    public String[] getParamMeta() {
        return null;
    }

    @Override
    public String[] getPropMeta() {
        //连通性， 延时 ，丢包率 
        return new String[] { "$1", "$2", "$3" };
    }

}
